﻿@model CMSApplication.Areas.Administration.Models.CustomerSearchModel
@{
    ViewBag.Title = "QL Khach hang";
}

<div class="row-fluid">
    <div class="span2">&nbsp;</div>
    <div class="span2">
        <span>Từ khóa</span>
    </div>
    <div class="span3">
        @Html.TextBoxFor(model => model.Keys, new { @style = "width:calc(100% - 14px);", @placeholder = "Tìm kiếm theo tên, điện thoại,..." })
    </div>
    <div class="span2">
        <span>Loại</span>
    </div>
    <div class="span3">
        @Html.DropDownListFor(model => model.Type, Model.SLType, new { @style = "width:100%;", @class = "select2-container" })
    </div>
</div>
<div class="row-fluid">
    <div class="span2">
        <a class="btn" href="@Url.Action("Add", "Customer", new { })">
            <span>Thêm mới</span>
        </a>
    </div>
    <div class="span2">
        <span>Ngày tạo (từ)</span>
    </div>
    <div class="span3">
        <input type="text" id="CreatedOnFrom" name="CreatedOnFrom" placeholder="Chọn ngày tạo (từ)" style="width:calc(100% - 14px);" />
    </div>
    <div class="span2">
        <span>Ngày tạo (đến)</span>
    </div>
    <div class="span3">
        <input type="text" id="CreatedOnTo" name="CreatedOnTo" placeholder="Chọn ngày tạo (đến)" style="width:calc(100% - 14px);" />
    </div>
</div>

<div class="head">
    <div class="isw-grid"></div>
    <h1>Quản lý khách hàng</h1>
    <div class="clear"></div>
</div>
<div class="block-fluid table-sorting">
    <div class="row-fluid list">
        @Html.Action("List", "Customer", new { page = 1 })
    </div>
</div>

<script>
    function GetDataForSearch(_data) {
        var created_on_from = ParseTime($("#CreatedOnFrom").val());
        var created_on_to = ParseTime($("#CreatedOnTo").val());
        return {
            Keys: $("#Keys").val().trim(),
            Type: parseInt($("#Type").val()),
            CreatedOnFrom: created_on_from != null ? created_on_from.toISOString() : null,
            CreatedOnTo: created_on_to != null ? created_on_to.toISOString() : null
        };
    };

    function ExecForSearch(_data) {
       Ajax({
            url: "/Customer/Search",
            type: "post",
            data: GetDataForSearch({}),
            ExecSuccess: function (result) {
                $(".list").html(result.dataServer);
                $.pnotify({
                    title: "Thông báo",
                    text: "Tìm kiếm hoàn tất",
                    type: "info",
                    opacity: .8
                });
            }
        });
    };

    (function ($) {
        $("#CreatedOnFrom, #CreatedOnTo").datepicker({
            // defaultDate: "+1w",
            dateFormat: "dd/mm/yy",
            changeMonth: true,
            changeYear: true,
            // numberOfMonths: 3
        });
        $("#CreatedOnFrom").datepicker("option", "onClose", function (selectedDate) {
            $("#CreatedOnTo").datepicker("option", "minDate", selectedDate);
        });
        $("#CreatedOnTo").datepicker("option", "onClose", function (selectedDate) {
            $("#CreatedOnFrom").datepicker("option", "maxDate", selectedDate);
        });
        $("#CreatedOnFrom, #CreatedOnTo").change(function (selectedDate) {
            ExecForSearch({});
        });
        $("#Type").change(function (e) {
            ExecForSearch({});
        });
        $("#Keys").keyup(function (e) {
            if (e.keyCode == 13) {
                ExecForSearch({});
            }
        })
    })(jQuery)
</script>
